package com.example.administrator.yuejian2.fragment;


import android.content.Intent;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.adapter.CommentAdapter;
import com.example.administrator.yuejian2.bean.CommentBean;
import com.example.administrator.yuejian2.model.CommentModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class CommentFragment extends Fragment {

    private RecyclerView recyclerView;
    private CommentAdapter commentAdapter;
    private String c_id;
    private RecyclerView.LayoutManager layoutManager;
    private RetrofitListener<List<CommentBean>> listener;
    public CommentFragment() {
        // Required empty public constructor
    }
private void initView(View view)
{
    recyclerView=view.findViewById(R.id.comment_recyclerview);
    layoutManager=new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    commentAdapter=new CommentAdapter(getActivity());
    recyclerView.setAdapter(commentAdapter);
}
private void CommentList()
{
    CommentModel commentModel=new CommentModel();
    commentModel.commentlist(c_id,listener);
}
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        //
        Intent intent = getActivity().getIntent();
        c_id = intent.getStringExtra("p_uid");
        listener=new RetrofitListener<List<CommentBean>>() {
            @Override
            public void onSuccess(List<CommentBean> commentBeans, int flag) {
                commentAdapter.commentdata(commentBeans);
            }

            @Override
            public void onFail() {

            }
        };
        View v=inflater.inflate(R.layout.fragment_comment, container, false);
        initView(v);
        CommentList();
        return v;
    }

}
